Skip to content

Fix Distance() witness points for overlapping shapes with useRadii - #320

Merged
shakiba merged 1 commit into
piqnt:masterfrom
bardrop-oss:fix-distance-witness-midpoint
Nov 14, 2026
Merged

shakiba merged 1 commit into
piqnt:masterfrom
bardrop-oss:fix-distance-witness-midpoint

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #318

When input.useRadii is set and the shapes overlap after the radii, Distance() should move both witness points to the middle (the comment says so, and Box2D uses 0.5f * (pointA + pointB)). Since the matrix refactor (b7ce8be) the line was matrix.subVec2(temp, pointA, pointB), so both points became pointA - pointB, e.g. (-1.5, 0) instead of (0.75, 0) for two unit circles 1.5 apart.

Now it is matrix.combine2Vec2(temp, 0.5, pointA, 0.5, pointB).

Testing

  • New test in src/__test__/Collision.test.ts: two overlapping circle cases from the issue (one away from the origin) plus a separated case that must keep the surface points. It fails on master, passes now.
  • npx vitest run (18 tests) passes; npm run lint shows the same 8 warnings as master.
  • Patch changeset added.

The matrix refactor replaced Vec2.mid(pointA, pointB) with
subVec2(pointA, pointB), so both witness points became pointA - pointB.
Use combine2Vec2(0.5, pointA, 0.5, pointB) like Box2D.

Fixes #318
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@bardrop is attempting to deploy a commit to the Piqnt Team on Vercel.

A member of the Team first needs to authorize it.

@shakiba
shakiba merged commit 068d621 into piqnt:master Nov 14, 2026
1 check failed
@shakiba

shakiba commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distance() with useRadii returns pointA - pointB instead of the midpoint for overlapping shapes

2 participants